// schema扩展相关文档请参阅：https://uniapp.dcloud.net.cn/uniCloud/jql-schema-ext.html
module.exports = {
	trigger: {
		 async afterRead({
			collection,
			operation,
			where,
			field,
			result
		} = {}) {
			if( Array.isArray(result.data) ){
				result.data.forEach(item=>{
					if(item.mobile){
						item.mobile = hideMobileStr(item.mobile)
					}
					if(item.email){
						item.email = hideEmailStr(item.email)
					}
				})
			}else{
				if(result.data.mobile){
					result.data.mobile = hideMobileStr(result.data.mobile)
				}
				if(result.data.email){
					result.data.email = hideEmailStr(result.data.email)
				}
			}
		}
	}
}

function hideEmailStr(email) {
  if (email == undefined) {
    return ''
  }
  const content = email.split("@")
  return content[0].substr(0, content[0].length - 2) + '**' + content[1]
}

function hideMobileStr(mobile){
	return mobile.substr(0,3) + '****'+ mobile.substr(-1*4)
}

